package com.sbcb.mongodb.entity;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

public class Order {
    private String orderID;
    private User user;
    private List<OrderItem> orderItemList = new ArrayList<>();
    private Double orderAmount;

    public Order() {
    }

    public String getOrderID() {
        return orderID;
    }

    public void setOrderID(String orderID) {
        this.orderID = orderID;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public List<OrderItem> getOrderItemList() {
        return orderItemList;
    }

    public void setOrderItemList(List<OrderItem> orderItemList) {
        this.orderItemList = orderItemList;
    }

    public Double getOrderAmount() {
        return orderAmount;
    }

    public void setOrderAmount(Double orderAmount) {
        this.orderAmount = orderAmount;
    }
    public void calculateAmount(){
        DecimalFormat format = new DecimalFormat("######0.00");
        Double amount = 0.0;
        for(OrderItem item: orderItemList){
            amount += item.getPrice();
        }
        this.orderAmount = Double.valueOf(format.format(amount));
    }
}
